//
// Created by Administrator on 2024/3/17.
//
// O(nlog(n))贪心算法：单一会场最多任务，按照终点排序（越早结束越优先）

#include<bits/stdc++.h>

using namespace std;
struct Item {//活动结构体
    int begin;
    int end;
} a[10000];
int n;

bool cmp(Item a, Item b) {//越早结束越优先
    return a.end < b.end;
}

int main() {
    while (cin >> n) {
        for (int i = 0; i < n; i++)
            cin >> a[i].begin >> a[i].end;
        sort(a, a + n, cmp);
        int tot = 0;
        int begin = 0;
        for (int i = 0; i < n; i++) {
            if (a[i].begin >= begin) {
                ++tot;
                begin = a[i].end;
            }
        }
        cout << tot << endl;

    }
}